'use strict';

angular.module('snPaas_om')
	.controller('UsersCtrl',['$scope','baseUrl','userStore',function($scope,baseUrl,userStore){
		var vm  = $scope;
		vm.baseUrl = baseUrl.static;
		var init = function(){
			userStore.getUsers(1).then(function(data){
				vm.nowPage = data.pageNow;
				vm.userlist = data.user;
				vm.pageCount = data.pageCount;
				console.log(vm);
			});
		};
		vm.goPage = function(page){
			if(page >vm.pageCount.length){
				page = vm.pageCount.length;
			}
			else if(page <1){
				page = 1;
			}

			if(page == vm.nowPage){
				return;
			}
			userStore.getUsers(page).then(function(data){
				console.log(data);
				vm.nowPage = data.pageNow;
				vm.userlist = data.user;
				vm.pageCount = data.pageCount;
				console.log(vm);

			});
		};
		vm.goPrev = function(){
			vm.goPage(vm.nowPage - 1);
		};
		vm.goNext = function(){
			vm.goPage(vm.nowPage + 1);
		};
		init();
	}])
	
	;